import string
import random
import time

def generate_invite_code(length: int = 10) -> str:
    """生成指定长度的邀请码（包含数字和大小写字母）"""
    # 定义字符集：大小写字母 + 数字
    chars = string.ascii_letters + string.digits
    # 随机选择字符生成邀请码
    return ''.join(random.choices(chars, k=length))

def cents_to_yuan_str(cents: int) -> str:
    """将分转换为元字符串，保留两位小数"""
    # return f"{cents / 100:.2f}"
    return f"{cents / 100}"

def yuan_str_to_cents(yuan: str) -> int:
    """将元字符串转换为分"""
    return int(round(float(yuan) * 100))

def cents_to_yuan_float(cents: int) -> float:
    """将分转换为元浮点数"""
    return float(cents) / 100

def yuan_float_to_cents(yuan: float) -> int:
    """将元浮点数转换为分"""
    return int(round(yuan * 100))

def gen_order_no(uid: int, prefix: str = "ORD") -> str:
    """生成订单号"""
    # 生成6位随机数
    rand = random.randint(100000, 999999)

    return f"{prefix}{int(time.time())}{rand}{uid%100}"
